package com.liankuan.console.repository;

import com.liankuan.console.dto.UserRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface UserRoleRepository extends JpaRepository<UserRole, Integer> {

    UserRole findByUserId(int userId);

    void deleteByUserId(int userId);

    @Query(value = "update user_role set role=?2 where user_id=?1", nativeQuery = true)
    @Modifying
    @Transactional
    void updateByUserId(int userId, String role);

}
